package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.enums.BasicEnum;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理")
@Slf4j
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }


    /**
     * 新增床位
     * @param bedDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "新增床位",notes = "传入床位对象")
    public ResponseResult create(@RequestBody BedDto bedDto){
        /**
         * 注意：
         * @RequestBody导包时
         * import org.springframework 才能接收到参数
         * import io.swagger.v3.oas 接收不到参数
         */
        log.info("新增床位：bedDto={}",bedDto);
        //接收参数
        //调用服务
         bedService.create(bedDto);
        //相应数据
        return ResponseResult.success();
    }

    /**
     * 根据ID查询床位信息
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据ID查询床位",notes = "传入床位ID")
    public ResponseResult read(@ApiParam(value = "床位ID",required = true) @PathVariable Long id){
        log.info("根据ID查询床位信息：{}",id);
        //调用服务
        BedVo bedVo = bedService.getBedById(id);
        return ResponseResult.success(bedVo);
    }

    /**
     * 更新床位信息
     * @param bedDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新床位信息",notes = "传入床位对象")
    public ResponseResult update( @RequestBody BedDto bedDto) {
        log.info("更新床位信息 {}",bedDto);
        //接收参数
        //调用服务
          bedService.update(bedDto);
        return ResponseResult.success();
    }

    /**
     * 根据ID删除床位
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "根据ID删除床位",notes = "传入床位ID")
    public ResponseResult delete(@ApiParam(value = "床位ID",required = true) @PathVariable Long id){
        log.info("根据ID删除床位");
        //调用服务
        bedService.delete(id);
        return ResponseResult.success("删除成功~");
    }
}
